package com.Txunda.fxw.ui.adapter;

import java.util.List;
import java.util.Map;

import com.Txunda.fxw.R;
import com.Txunda.fxw.ui.activity.other.DetailAty;
import com.Txunda.fxw.ui.callback.MyItemClickListener;
import com.Txunda.fxw.ui.activity.law.Law_firmAty;
import com.Txunda.fxw.ui.adapter.model.BottomDetailViewHolder;
import com.bumptech.glide.Glide;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class BottomLawAdapter extends RecyclerView.Adapter<BottomDetailViewHolder> {

    private List<Map<String, String>> list;
    MyItemClickListener itemClickListener;

    Activity act;

    public List<Map<String, String>> getList() {
        return list;
    }

    public void setList(List<Map<String, String>> list) {
        this.list = list;
    }

    public BottomLawAdapter(MyItemClickListener itemClickListener, Activity act) {
        // this.mContext = context;
        this.itemClickListener = itemClickListener;
        this.act = act;
    }

    @Override
    public int getItemCount() {
        int ret = 0;
        if (list != null) {
            ret = list.size();
        }
        return ret;
    }

    @Override
    public void onBindViewHolder(BottomDetailViewHolder holder, final int position) {
        final String name = list.get(position).get("name");
        if (name.equals("")) {
            holder.getBottom_detail_img().setVisibility(View.INVISIBLE);
            holder.getBottom_detail_title().setVisibility(View.INVISIBLE);
        } else {
            holder.getBottom_detail_img().setVisibility(View.VISIBLE);
            holder.getBottom_detail_title().setVisibility(View.VISIBLE);
//            imageLoader.disPlay(holder.getBottom_detail_img(), list.get(position).get("cover_pic"));
            Glide.with(act).load(list.get(position).get("cover_pic")).into(holder.getBottom_detail_img());

            holder.getBottom_detail_title().setText(list.get(position).get("name"));
        }
        final String com_id = list.get(position).get("com_id"); // 商家id
        final String class_id = list.get(position).get("class_id");
        final String type = list.get(position).get("type");

        final String o_id = list.get(position).get("o_id");
        final String district_id = list.get(position).get("district_id");

        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (name.equals("")) {
                    return;
                }
                if ("0".equals(type)) { // 普通商家
                    Intent intent = new Intent(act, DetailAty.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("com_id", com_id);
                    bundle.putString("class_id", class_id);
                    bundle.putString("name", name);

                    intent.putExtras(bundle);
                    act.startActivity(intent);
                } else if ("1".equals(type)) { // 律师事务所
                    Intent intent = new Intent(act, Law_firmAty.class);
                    Bundle bundle = new Bundle();
                    String area_name = list.get(position).get("area_name");
                    bundle.putString("district_id", com_id);
                    bundle.putString("district_name", area_name);

                    intent.putExtras(bundle);

                    act.startActivity(intent);
                }

                act.finish();

            }
        });
    }

    @Override
    public BottomDetailViewHolder onCreateViewHolder(ViewGroup arg0, int arg1) {
        View view = LayoutInflater.from(act).inflate(R.layout.item_bottom_detail2, null);
        BottomDetailViewHolder detailRecyclerHolder = new BottomDetailViewHolder(view);
        return detailRecyclerHolder;
    }

}
